﻿@model MvcShoppingMall.ViewModels.ShoppingCartViewModel

@{
    ViewBag.Title = "ShoppingCar";
    Layout = "~/Views/Shared/_HeadAndEnd.cshtml";
}

<script src="/Scripts/jquery- 1.4.4.min.js" type="text/javascript"></script>
<link href="~/Content/css/ziy.css" rel="stylesheet" />
<link href="~/Content/css/carts.css" rel="stylesheet" />
<link href="~/Content/css/reset.css" rel="stylesheet" />
<script src="~/Content/js/carts.js"></script>
<script src="~/Content/js/jquery.min.js"></script>
<script type="text/javascript">

    $(function () {
        // 页面打开时在点击链接的时候执行删除操作
        $("#RemoveLink").click(function () {
            //取得链接中的ID
            var recordToDelete = $(this).attr("data-id");
            if (recordToDelete != '') {
                // 执行ajax调用
                $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
                    function (data) {
                        // 删除成功时执行的代码
                        // 更新页面元素
                        if (data.ItemCount == 0) {
                            $('#row-' + data.DeleteId).fadeOut('slow');
                        } else {
                            $('#item-count-' + data.DeleteId).text(data.ItemCount);
                        }
                        $('#cart-total').text(data.CartTotal);
                        $('#update-message').text(data.Message);
                        $('#cart-status').text('Cart (' + data.CartCount + ')');
                    });
            }
        });
    });
    function handleUpdate() {
        //装载并解析JSON对象
        var json = context.get_data();
        var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);

        // 更新页面元素
        if (data.ItemCount == 0) {
            $('#row-' + data.DeleteId).fadeOut('slow');
        } else {
            $('#item-count-' + data.DeleteId).text(data.ItemCount);
        }
        $('#cart-total').text(data.CartTotal);
        $('#update-message').text(data.Message);
        $('#cart-status').text('Cart (' + data.CartCount + ')');
    }
</script>
<div id="update-message">
</div>
<div class="yiny yiny_gouwc">
    <div class="beij_center">
        <div class="dengl_logo">
            <a href="@Url.Action("Index","Home")"><img src="~/Content/images/logo_1.png"></a>
            <h1>购物车</h1>
        </div>
    </div>
</div>
<div class="container">

    <div class="cart-login-tip fl" id="idnotlogin" act-not-login-info="" style="display: none;">
        您还没有登录！登录后购物车的商品将保存到您账号中。
        <a class="cart-login-btn" href="dengl.html">
            立即登录
        </a>
    </div>
</div>
<section class="cartMain">
    <div class="cartMain_hd">
        <ul class="order_lists cartTop">
            <li class="list_chk">
                <!--所有商品全选-->
                <input type="checkbox" id="all" class="whole_check">
                <label for="all"></label>
                <strong>全选</strong>

            </li>
            <li class="list_con">商品信息</li>
            <li class="list_info">商品参数</li>
            <li class="list_price">单价</li>
            <li class="list_amount">数量</li>
            <li class="list_sum">金额</li>
            <li class="list_op">操作</li>
        </ul>
    </div>

   
        <div class="order_content">

            @foreach (MvcShoppingMall.Model.Cart item in ViewBag.delect)
            {
                
                <ul class="order_lists" style="height:150px;">
                    <li class="list_chk">
                        <input type="checkbox" id="checkbox_@(item.CartId)" class="son_check">

                        <label for="checkbox_@(item.CartId)"></label>
                    </li>
                    <li class="list_con">

                        <div class="list_img"><a href="javascript:;"><img src="~/Content/images/dyImg/@item.wst_goods.goodsImg"></a></div>
                        <div class="list_text"><a href="javascript:;" id="row-@item.RecordId">@Html.ActionLink(item.wst_goods.goodsName, "GoodsDatails", "Home", new { id = item.goodsId })</a></div>
                    </li>
                    <li class="list_info">
                        <p>规格：@item.wst_goods_specs.isDefault</p>

                    </li>
                    <li class="list_price">
                        <p class="price">￥@item.wst_goods.shopPrice</p>
                    </li>
                    <li class="list_amount">
                        <div class="amount_box">
                            <a href="javascript:;" class="reduce reSty">-</a>
                            <input type="text" value=" @item.Count " class=" sum" readonly="true" id="item-count-@item.RecordId">
                            <a href="javascript:;" class="plus">+</a>
                        </div>
                    </li>
                    <li class="list_sum">
                        @{
                var price = item.Count * item.wst_goods.shopPrice;
                        }
                        <p class="sum_price">￥@price</p>
                    </li>
                    <li class="list_op">

                        <p class="del"><a href="#" id="RemoveLink" onclick="DeleGoods(@item.CartId)" data-id="@item.goodsId">删除</a></p>
                    </li>
                </ul>
            }
        </div>
    </div>
    <script>
        function DeleGoods(id) {
            if (confirm("确认删除吗？")) {
                $.post("@Url.Action("DeleShoppinCar", "Home")",
                    { id: id },
                    function (data) {
                        if (data == "OK") {
                            alert('删除成功！');
                            location.reload();
                        } else {
                            alert('删除失败！！！');
                        }
                    });
            }
        }
    </script>



    <div class="bar-wrapper">

        &nbsp;  &nbsp;


        <div class="bar-right">

            <div class="piece">已选商品<strong class="piece_num">0</strong>件</div>
            <div class="totalMoney">共计: <strong class="total_text">0</strong></div>
            <div class="calBtn">@Html.ActionLink("结算", "ShopClear", "Home")</div>

        </div>
    </div>
</section>
<section class="model_bg"></section>
<div class="my_model">
    <p class="title">删除宝贝<span class="closeModel">X</span></p>
    <p>您确认要删除该宝贝吗？</p>
    <div class="opBtn"><a href="javascript:;" class="dialog-sure">确定</a><a href="javascript:;" class="dialog-close">关闭</a></div>
</div>
